﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using T3Task5;

namespace chaoshiguanli
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
                //获取员工输入的账号和密码
                string userName = this.textBox1.Text;
                string passName = this.textBox2.Text;
                //非空验证
                if (userName == "" || passName == "")
                {
                    MessageBox.Show("用户名和密码不能为空！", "提示");
                }
                else
                {
                    bool result = false;
                    //登录
                    string sql = string.Format("select * from Account where userName='{0}'and passName='{1}'", userName, passName);
                    SqlDataReader dr = DBHelper.Select(sql);
                    while (dr.Read())
                    {
                        MessageBox.Show("登陆成功！欢迎使用笙莜超市管理系统😀", "提示");
                        this.Hide();
                        Form3 form3 = new Form3();
                        form3.Show();
                        result = true;
                        break;

                    }
                    //登陆失败   
                    if (!result)
                    {
                        MessageBox.Show("登陆失败！", "提示");
                    }
                }
            
            
        }

        private void login_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.AcceptButton = button1;
            this.CancelButton = button1;
        }

        private void label2_Click(object sender, EventArgs e)
        {
            label1.BackColor = Color.Transparent;
        }

        private void login_Load(object sender, EventArgs e)
        {
            BackgroundImage = Image.FromFile("img/tp2.jpg");
        }
    }
}
